﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using MingYuanyun.WebApi.Abstractions;

namespace ControlCenterService.WebApi.Internal
{
    /// <summary>
    /// API权限验证过滤器
    /// </summary>
    public class ClientApiFilter : ActionFilterAttribute
    {
        private bool _isValid = false;

        /// <summary>
        /// OnActionExecuting
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
            //string appid = context.HttpContext.Request.Headers["AppId"];
            //string appToken = context.HttpContext.Request.Headers["AppToken"];
            //if (appid == "app1" && appToken == "TESTTOKEN123456")
            //{
            //    base.OnActionExecuting(context);
            //}
            //else
            //{
            //    context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
            //    context.Result = new JsonResult(new HttpRequestResult(null, false, "未授权！", string.Empty));
            //}
        }

        /// <summary>
        /// OnActionExecuted
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            base.OnActionExecuted(context);
        }
    }
}
